package com.example.weibo;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;

import android.os.Bundle;
import android.view.MenuItem;

import com.google.android.material.bottomnavigation.BottomNavigationItemView;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.navigation.NavigationBarView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        NavController navController = Navigation.findNavController(this, R.id.fragment);
        BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_navigation_view);

        bottomNavigationView.setOnItemSelectedListener(new NavigationBarView.OnItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.tab1:
                        navController.navigate(R.id.mainFragment);
                        break;
                    case R.id.tab2:
                        navController.navigate(R.id.videoFragment);
                        break;
                    case R.id.tab3:
                        navController.navigate(R.id.searchFragment);
                        break;
                    case R.id.tab4:
                        navController.navigate(R.id.messageFragment);
                        break;
                    case R.id.tab5:
                        navController.navigate(R.id.myFragment);
                        break;
                }
                return true;
            }
        });
    }
}